package cn.seocoo.platform.api.controller;

import cn.seocoo.platform.api.util.JSONResult;
import cn.seocoo.platform.common.core.domain.AjaxResult;
import cn.seocoo.platform.common.utils.StringUtils;
import cn.seocoo.platform.top.dto.TopTypeDto;
import cn.seocoo.platform.top.service.ITopTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ApiTopController
 * @description: 置顶类型选择
 * @author: wujian
 * @Date: 2019-12-26 14:11
 **/
@RequestMapping("api/top")
@RestController
public class ApiTopController {

    @Autowired
    private ITopTypeService iTopTypeService;

    /**
     * @return cn.seocoo.platform.common.core.domain.AjaxResult
     * @Author WuJian
     * @Description //获取所有的置顶类型
     * @Date 14:22 2019/12/26
     * @Param []
     **/
    @GetMapping("/getTopTypeList")
    public JSONResult getTopTypeList() {
        List<TopTypeDto> list = iTopTypeService.getTopTypeList();
        return JSONResult.ok(list);
    }


    @PostMapping("/getAmount")
    public JSONResult getAmount(@RequestBody ModelMap map) {
        try {
            if (StringUtils.isNull(map.get("id"))) {
                return JSONResult.errorMsg("请选择置顶类型");
            }
            if (StringUtils.isNull(map.get("day"))) {
                return JSONResult.errorMsg("请选择置顶天数");
            }
            String amount = iTopTypeService.getAmount(Integer.valueOf(map.get("id").toString()), Integer.valueOf(map.get("day").toString()));
            return JSONResult.ok(amount);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.errorMsg(JSONResult.ERROR_MSG);
        }

    }
}
